﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Lidgren.Network;

namespace CodeGame.Networking.Clientside
{
    class ClientProtocolDatabase
    {
        public static void SetKey(string table, string key, string value)
        {
            SendDataMessage(DatabaseCommands.SetKey, table, key, value);
        }

        public static void GetKey(string table, string key)
        {
            SendDataMessage(DatabaseCommands.GetKey, table, key, "");
        }

        public static void AddValue(string table, string value)
        {
            SendDataMessage(DatabaseCommands.AddValue, table, "", value);
        }

        public static void GetAllKeys(string table)
        {
            SendDataMessage(DatabaseCommands.GetAllKeys, table, "", "");
        }

        private static void SendDataMessage(DatabaseCommands type, string table, string key, string value)
        {
            NetOutgoingMessage message = Singletons.Network.CreateMessage(ClientServerNet.DatabaseRequest);

            message.Write((int)DatabaseCommands.GetKey);
            message.Write(table);
            message.Write(key);
            message.Write(value);

            Singletons.Network.SendMessage(message);
        }
    }
}
